<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */
?>
<?=$this->header(true)?>


    <?=$this->menu("content")?>


    <h1><?=$this->message("label.header", _Content::BUNDLE)?></h1>


    <? /* Breadcrums route */ ?>
    <?=$this->route(
        array(
            array(
                "name"=>$this->message("label.category.header", _Content::BUNDLE),
                "href"=>"content/category/list"
            ),
            array(
                "name"=>$this->category($this->contentForm->getContentI18n()->getContent()->getCategoryId()),
                "href"=>"content/list"
            ),
            array(
                "name"=>$this->languageRoute(
                            $this->message("label.item", _Content::BUNDLE),       // Item name
                            $this->contentForm->getContentI18n()->getDefaultName(
                                $this->param(_Core::DEFAULT_LANGUAGE)),        // Default language item name
                            $this->contentForm->getContentI18n()->getContentI18nId(),  // Id
                            $this->contentForm->getContentI18n()->getLanguage()) // Language
            )
        )
    )?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Content::BUNDLE)?>


    <form id="<?=get_class($this->contentForm)?>" action="content/save" method="post" enctype="multipart/form-data">

        <div>
            <input type="hidden"
                   name="contentI18n->contentId"
                   value="<?=$this->contentForm->getContentI18n()->getContentId()?>" />
            <input type="hidden"
                   name="contentI18n->contentI18nId"
                   value="<?=$this->contentForm->getContentI18n()->getContentI18nId()?>" />
            <input type="hidden"
                   name="contentI18n->languageCode"
                   value="<?=$this->contentForm->getContentI18n()->getLanguageCode()?>" />
            <input type="hidden"
                   name="contentI18n->content->categoryId"
                   value="<?=$this->contentForm->getContentI18n()->getContent()->getCategoryId()?>" />
        </div>

        <fieldset>

            <legend><?=$this->message("label.required", _Core::BUNDLE)?></legend>

            <table cellspacing="0" cellpadding="0" class="form">
            <tr class="ctrl<?=$this->error("contentI18n->name")?>">
                <th><label for="contentI18n_name"><?=$this->message("prompt.name", _Content::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <input name="contentI18n->name"
                           id="contentI18n_name"
                           value="<?=$this->contentForm->getContentI18n()->getName()?>"
                           maxlength="30"
                           type="text"
                           class="textInput" />
                </td>
            </tr>
            <tr class="ctrl<?=$this->error("contentI18n->body")?>">
                <th><label for="contentI18n_body"><?=$this->message("prompt.body", _Content::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <textarea id="contentI18n_body" name="contentI18n->body" mce_editable="true" rows="20" cols="80"><?=!is_null($this->contentForm->getContentI18n()->getBody()) ?
                        htmlspecialchars($this->contentForm->getContentI18n()->getBody()->getContents()) : ""?></textarea>
                    <p class="hint"><?=$this->message("note.image", _Core::BUNDLE, null, null, false)?></p>
                </td>
            </tr>
            </table>

        </fieldset>

        <fieldset>

            <legend><?=$this->message("label.optional", _Core::BUNDLE)?></legend>

            <table cellspacing="0" cellpadding="0" class="form">
            <tr class="ctrl<?=$this->error("contentI18n->intro")?>">
                <th><label for="contentI18n_intro"><?=$this->message("prompt.intro", _Content::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <textarea id="contentI18n_intro" name="contentI18n->intro" rows="7" cols="80"><?=!is_null($this->contentForm->getContentI18n()->getIntro()) ?
                        $this->contentForm->getContentI18n()->getIntro()->getContents() : ""?></textarea>
                    <p class="hint"><?=$this->message("note.intro", _Core::BUNDLE)?></p>
                </td>
            </tr>

            <? /* Only show optional fields with default language contents */ ?>
            <? if($this->contentForm->getContentI18n()->getLanguageCode() == $this->param(_Core::DEFAULT_LANGUAGE)): ?>
            <tr class="ctrl<?=$this->error("contentI18n->content->author")?>">
                <th><label id="contact-label" for="contentI18n_content_author"><?=$this->message("prompt.author", _Content::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <input name="contentI18n->content->author"
                           id="contentI18n_content_author"
                           value="<?=$this->contentForm->getContentI18n()->getContent()->getAuthor()?>"
                           maxlength="64"
                           type="text"
                           class="textInput" />
                    <p id="contact-note" class="hint">&nbsp;</p>
                </td>
            </tr>
            <tr class="ctrl<?=$this->error("day")?><?=$this->error("month")?><?=$this->error("year")?>">
                <th>
                    <?=$this->message("prompt.date", _Content::BUNDLE)?>
                    <p class="hint">(<label for="day"><?=$this->message("prompt.day", _Content::BUNDLE)?></label>/<label for="month"><?=$this->message("prompt.month", _Content::BUNDLE)?></label>/<label for="year"><?=$this->message("prompt.year", _Content::BUNDLE)?></label>)</p>
                </th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <?=$this->formDays(
                        "day",
                        $this->contentForm->getDay()
                    )?>
                    <?=$this->formMonths(
                        "month",
                        $this->contentForm->getMonth()
                    )?>
                    <?=$this->formYears(
                        "year",
                        $this->contentForm->getYear()
                    )?>
                </td>
            </tr>
            <tr class="ctrl<?=$this->error("formImage")?>">
                <th><label for="formImage"><?=$this->message("label.image", _Core::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <? if(!is_null($this->contentForm->getContentI18n()->getContent()) &&
                        $this->contentForm->getContentI18n()->getContent()->getImageId() > 0 &&
                        !is_null($this->contentForm->getContentI18n()->getContent()->getImageRelatedByImageId())) { ?>

                        <input type="hidden"
                               name="contentI18n->content->imageRelatedByImageId->imageId"
                               value="<?=$this->contentForm->getContentI18n()->getContent()->getImageId()?>" />
                        <input type="hidden"
                               name="contentI18n->content->imageRelatedByThumbnailId->imageId"
                               value="<?=$this->contentForm->getContentI18n()->getContent()->getThumbnailId()?>" />

                        <input type="hidden"
                               name="contentI18n->content->imageRelatedByImageId->binaryFileId"
                               value="<?=$this->contentForm->getContentI18n()->getContent()->getImageRelatedByImageId()->getBinaryFileId()?>" />
                        <input type="hidden"
                               name="contentI18n->content->imageRelatedByThumbnailId->binaryFileId"
                               value="<?=$this->contentForm->getContentI18n()->getContent()->getImageRelatedByThumbnailId()->getBinaryFileId()?>" />

                        <img src="image?id=<?=$this->contentForm->getContentI18n()->getContent()->getImageId()?>"
                             width="<?=$this->contentForm->getContentI18n()->getContent()->getImageRelatedByImageId()->getWidth()?>"
                             height="<?=$this->contentForm->getContentI18n()->getContent()->getImageRelatedByImageId()->getHeight()?>" alt="" />

                        <input type="checkbox" name="deleteImage" value="true" id="deleteImage" /> <label for="deleteImage"><?=$this->message("label.image.delete", _Core::BUNDLE)?></label>

                        <br /><br />

                    <? } ?>

                    <input type="file" name="formImage" />

                    <p class="hint"><?=$this->message("note.image.resize", _Core::BUNDLE)?> <?=$this->imageProps($this->param(_Core::SETTING_LIST))->getImageWidth()?>x<?=$this->imageProps($this->param(_CORE::SETTING_LIST))->getImageHeight()?>.</p>

                </td>
            </tr>
            <? endif; ?>

            </table>

        </fieldset>

        <div class="buttons">

            <input type="button"
                   onclick="to('content/list')"
                   value="<?=$this->message("button.cancel", _Core::BUNDLE)?>"
                   class="button" />
            <input type="submit"
                   value="<?=$this->message("button.submit", _Core::BUNDLE)?>"
                   class="button" />

        </div>

    </form>

<?=$this->footer()?>